﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using System.Xml.Serialization;
using NielsDerdaele.HttpSocket.Example.Phone.DTO;

namespace NielsDerdaele.HttpSocket.Example.Phone {
    public partial class MainPage : PhoneApplicationPage {        
        // Constructor
        HttpSocket.Phone.HttpClientSocket socket;
        public MainPage() {
            InitializeComponent();
            var s = new NielsDerdaele.HttpSocket.Phone.HttpClientSocket();            
            s.ConnectCompleted += new EventHandler<System.ComponentModel.AsyncCompletedEventArgs>(s_ConnectCompleted);
            s.BeginConnect("localhost", 1330);
            socket = s; 
        }

        void s_ConnectCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e) {
            if (e.Error == null) {
                var ser = new XmlSerializer(typeof(ChatMessage));
                ser.Serialize(new HttpSocket.Phone.HttpClientStream(socket), new ChatMessage { Username = "niels", Message = "halloo ik ben niels!" });
                
                ser.Serialize(new HttpSocket.Phone.HttpClientStream(socket), new ChatMessage { Username = "niels", Message = "halloo ik ben niels!" });
                
                /*ser.Serialize(new HttpSocket.Phone.HttpClientStream(socket), new ChatMessage { Username = "niels", Message = "halloo ik ben niels!" });
                
                /*ser.Serialize(new HttpSocket.Phone.HttpClientStream(socket), new ChatMessage { Username = "niels", Message = "halloo ik ben niels!" });
                ser.Serialize(new HttpSocket.Phone.HttpClientStream(socket), new ChatMessage { Username = "niels", Message = "halloo ik ben niels!" });            */
            }
        }
    }
}